/* Dances with Balrog
 Warrior Job Advancement
 Victoria Road : Warriors' Sanctuary (102000003)
 
 Custom Quest 100003, 100005
 */

var status = 0;
var job;


function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == 0 && status == 2) {
        cm.sendOk("下决心再来看我！");
        cm.dispose();
        return;
    }
    if (mode == 1)
        status++;
    else
        status--;
    if (status == 0) {
        if (cm.getJob() == 0) {
            if (cm.getPlayerStat("LVL") >= 10 && cm.getJob() == 0) {
                cm.sendNext("所以你决定成为 #r战士职业#k?");
            } else {
                cm.sendOk("再多训练一点，我可以告诉你 #r战士职业#k.");
                cm.dispose();
            }
        } else {
            if (cm.getPlayerStat("LVL") >= 30 && cm.getJob() == 100) { // WARROPR
                if (cm.getQuestStatus(100003) >= 1) {
                    cm.completeQuest(100005);
                    if (cm.getQuestStatus(100005) == 2) {
                        status = 20;
                        cm.sendNext("我看你干得不错。我会让你在你漫长的道路上迈出下一步.");
                    } else {
                        if (!cm.haveItem(4031008)) {
                            cm.gainItem(4031008, 1);
                        }
                        cm.sendOk("去看看 #r职业指导书#k.")
                        cm.dispose();
                    }
                } else {
                    status = 10;
                    cm.sendNext("你所取得的进步是惊人的.");
                }
            } else if (cm.getQuestStatus(100100) == 1) {
                cm.completeQuest(100101);
                if (cm.getQuestStatus(100101) == 2) {
                    cm.sendOk("好的，现在把这个拿给 #b太拉斯#k.");
                } else {
                    cm.sendOk("Hey, #b#h0##k! I need a #bBlack Charm#k. Go and find the Door of Dimension.");
                    cm.startQuest(100101);
                }
                cm.dispose();
            } else {
                cm.sendOk("You have chosen wisely.");
                cm.dispose();
            }
        }
    } else if (status == 1) {
        cm.sendNextPrev("It is an important and final choice. You will not be able to turn back.");
    } else if (status == 2) {
        cm.sendYesNo("Do you want to become a #rWarrior#k?");
    } else if (status == 3) {
        if (cm.getJob() == 0) {
            cm.resetStats(35, 4, 4, 4);
            cm.expandInventory(1, 4);
            cm.expandInventory(4, 4);
            cm.changeJob(100); // WARRIOR
            //cm.gainSp(3);
        }
        cm.gainItem(1402001, 1);
        cm.sendOk("So be it! Now go, and go with pride.");
        cm.dispose();
    } else if (status == 11) {
        cm.sendNextPrev("You may be ready to take the next step as a #rFighter#k, #rPage#k or #rSpearman#k.")
    } else if (status == 12) {
        cm.askAcceptDecline("But first I must test your skills. Are you ready?");
    } else if (status == 13) {
        cm.gainItem(4031008, 1);
        cm.startQuest(100003);
        cm.sendOk("Go see the #bJob Instructor#k near Perion. He will show you the way.");
        cm.dispose();
    } else if (status == 21) {
        cm.sendSimple("What do you want to become?#b\r\n#L0#Fighter#l\r\n#L1#Page#l\r\n#L2#Spearman#l#k");
    } else if (status == 22) {
        var jobName;
        if (selection == 0) {
            jobName = "Fighter";
            job = 110; // FIGHTER
        } else if (selection == 1) {
            jobName = "Page";
            job = 120; // PAGE
        } else {
            jobName = "Spearman";
            job = 130; // SPEARMAN
        }
        cm.sendYesNo("Do you want to become a #r" + jobName + "#k?");
    } else if (status == 23) {
        cm.changeJob(job);
        cm.gainItem(4031012, -1);
        cm.sendOk("So be it! Now go, and go with pride.");
        cm.dispose();
    }
}
